const vuemethod = {

    loadToken() {
        this.tokenJson = tool.parseTokenObject(this.tokenObject)
    },

    loadTableData() {
        axi.get(this,"/" + this.a + "/" + this.b + "/" + this.c + "/" + "page", this.searchForm, data => {
            this.tableData = data.list
            this.pagination.total = data.total
        } )
    },

    loadAbc() {
        axi.get(this,  '/auth/sysinfo/menu' + '/abc'  , { a: this.a, b: this.b, c: this.c },  data => {
            if (data) {
                this.abc = data
                //
                this.activeMenu = this.abc.entity.flag
                this.openMenu = [this.abc.module.flag]
            }
        })
    },

    loadDict() {
        const codes = this.dicts.map(_ => _.tag).join(';')
        axi.get(this,  '/project/test/dict' + '/batch'  , { codes: codes },  data => {
            if (data ) {
                for (var i = 0; i < data.length; i++) {
                    const list = data[i]
                    const top = [{id: '', name: this.dicts[i].name}]
                    // const top = []
                    this.dicts[i].list = [...top, ...list]
                }
            }
            //
            this.loadTableData()
        })
    },

    seePassword(id) {
        this.passwordForm.password = ''
        this.passwordForm.username = ''
        this.fileList = []
        //
        this.dialogVisiblePassword = true
        this.currentUploadId = id
    },

    handleClosePassword() {
        this.dialogVisiblePassword = false
    },

    insertData() {
        this.dialogLoading = true
        const flag = this.dialogTitle === '新增'
        if (flag) {
            this.toInsert()
        }   else {
            this.toUpdate()
        }
    },

    toInsert() {
        this.formData.id = undefined
        axi.post(this,"/" + this.a + "/" + this.b + "/" + this.c + "/" + 'insert',  this.formData, data => {
            this.showBtnDialogFormSubmit = true
            //
            this.$message.success('保存成功')
            this.loadTableData()
            this.handleClose()
            this.dialogLoading = false
        } )
    },

    toUpdate() {
        axi.put(this,"/" + this.a + "/" + this.b + "/" + this.c + "/" + 'update_by_id',  this.formData, data => {
            this.showBtnDialogFormSubmit = true
            //
            this.$message.success('保存成功')
            this.loadTableData()
            this.handleClose()
            this.dialogLoading = false
        } )
    },

    searchByFilter() {
        this.searchForm.cpage = 1
        this.searchForm.csize = this.pagination.pageSize
        this.loadTableData()
    },


    dialogFormSubmit() {
        this.$refs.submitDialogFormRef.validate((valid) => {
            if (valid) {
                this.showBtnDialogFormSubmit = false
                    // 执行插入操作
                    this.insertData()
            } else {
                return false;
            }
        })
    },

    resetClear(){
        this.searchForm = {
                categoryDictId: '',
                typeDictId: '',
                 title: '',
                 detail: '',
        }
        //
        this.secondList = [{id: '', name: '------ 技术分类 ------'}]
        this.searchByFilter()
    },



    action(op, row) {
        this.$nextTick(() => {
            switch (op) {
                case 'add':  this.addAction();  break;
                case 'edit': this.editAction();  break;
                case 'delete':  this.deleteAction();  break;
                case 'copy':  this.copyAction();  break;
            }
        })

    },

    addAction() {
        this.dialogTitle = '新增'
        //
        // for (var i = 0; i < this.dicts.length; i++) {
        //     const list = this.dicts[i].list
        //     //
        //     const lastList = list.filter(item => item.name == this.dicts[i].value)
        //     if (lastList && lastList.length > 0) {
        //         const selId = lastList[0].id
        //         this.formData[this.dicts[i].field] = selId
        //     }
        // }
        //

        //
        this.formData = {
            categoryDictId: '',
            typeDictId: '',
            title: '',
            detail: '',
            icon: 'search',
        }

        this.showBtnDialogFormSubmit = true
        if (this.$refs.submitDialogFormRef) {
            this.$refs.submitDialogFormRef.resetFields()
        }
        this.dialogVisible = true
    },

    editAction() {

        if (this.sels.length != 1) {
            this.$message.error('请仅只选择一条记录！')
            return false
        }
        else {
            this.dialogTitle = '编辑'
            //
            this.formData = this.sels[0]
            this.formData.updatePasswordFlag = 0

            //
            const topId = this.formData.categoryDictId
            if ( topId == undefined || topId == null ||  topId == '') {
                this.secondList = [{id: '', name: '------ 技术分类 ------'}]
            } else {
                const tmp = [{id: '', name: '------ 技术分类 ------'}]
                const data = this.firstList.filter(item => item.id == topId)[0].valueList
                this.secondList = [...tmp, ...data]
            }

            this.showBtnDialogFormSubmit = true
            if (this.$refs.submitDialogFormRef) {
                this.$refs.submitDialogFormRef.resetFields()
            }
            this.dialogVisible = true
        }
    },


    deleteAction() {
        if (this.sels.length < 1) {
            this.$message.error('请至少选择一条记录！')
            return false
        } else {
            this.$confirm('确定要删除这 <span style="color:red;">' + this.sels.length + '</span> 条记录吗？', '警示', {
                dangerouslyUseHTMLString: true,
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                const ids = this.sels.map(_ => _.id).join(',')
                console.log(ids, ' ids')
                const full = "/" + this.a + "/" + this.b + "/" + this.c + "/"
                axi.delete(this, full + 'remove_ids',  ids, data => {
                    //
                    this.$message.success('删除成功');
                    this.loadTableData()
                } )
            }).catch((e) => {
                log.error(e)
            })
        }

    },


    copyAction() {
        if (this.sels.length != 1) {
            this.$message.error('请仅只选择一条记录！')
            return false
        }
        else {
            const id = this.sels[0].id
            axi.post(this,"/" + this.a + "/" + this.b + "/" + this.c + "/" + 'copy',  {id: id}, data => {
                //
                this.$message.success('复制成功')
                this.loadTableData()
                this.handleClose()
            } )
        }
    },



    // 切换菜单折叠状态
 toggleCollapse() {
    this.isCollapse = !this.isCollapse;
},
    // 添加菜单点击处理方法
    handleSelect(index, indexPath) {
    this.activeMenu = index;
    // 根据需要处理路由跳转或其他逻辑
},

    handleSizeChange(val) {
        this.pagination.pageSize = val
        this.searchForm.csize = val
        his.searchForm.cpage = val
        this.searchForm.csize = this.pagination.pageSize
        this.loadTableData()
    },

    handleCurrentChange(val) {
        this.pagination.currentPage = val
        this.searchForm.cpage = val
        this.searchForm.csize = this.pagination.pageSize
        this.loadTableData()
    },






    showMessages() {
    // TODO: 显示消息列表
    this.$message({
        message: '您有3条未读消息',
        type: 'info'
    });
},
    logOutPage() {
    window.location.href = '/pc' + '/login';
},
    clearCompletedTodos() {
    this.todos = this.todos.filter(todo => !todo.done);
},
    loadMenus() {
    axi.get(this, '/auth/sysinfo/menu/' + 'sidebar' + '/' + this.sysinfoMicroId , {}, data => {
        if (data && data.length > 0) {
            this.menuList = data
        }
    })
},
    openUrl(dir, item) {
        const tmp = "fc6ffcc43019b074f54f4b0de831257bc087a0c6f7c6f310267b23c258068c80Ab5e09fa288c363d73f894e08a0dcc3eb0fa830a0862dda8093dc60211cf802ac"
        const last = this.pre + '/html/' + this.a + '/' + dir.url + '/' + item.url + '/' + 'index' + '/' + this.tokenJson.token + "A" + tmp + "?t=" + new Date().getTime() + "&sysinfoMicroId=" + this.sysinfoMicroId  + "&gogogocode=" + this.gogogocode
        window.location.href = last
    },
    goHomePage() {
        const tmp = "fc6ffcc43019b074f54f4b0de831257bc087a0c6f7c6f310267b23c258068c80Ab5e09fa288c363d73f894e08a0dcc3eb0fa830a0862dda8093dc60211cf802ac"
        const last = this.pre + '/html/' + this.a  + this.abc.micro.root + '/' + 'index' + '/' + this.tokenJson.token + "A" + tmp + "?t=" + new Date().getTime() + "&sysinfoMicroId=" + this.sysinfoMicroId  + "&gogogocode=" + this.gogogocode
        window.location.href = last;
},
    copyById(id) {
    this.$message.info(id)
},

    trans(row) {
    const res = tool.objToKvList(row)
    return res;
},

    loadRole() {
    axi.get(this,  '/auth/sysinfo/role' + '/role_by_token_id/' + this.tokenJson.id  , {},  data => {
        if (data) {
            this.role = data ;
        }
    })
},



        handleClose() {
            this.dialogVisible = false
        },




}
